<template>
  <div class="contenter">
    <el-row>
      <el-col :span="12" :xs="0"></el-col>
      <el-col :span="12" :xs="24">
        <div class="right">
          <div class="top">
            <svg-icon name="tu" width="110px" height="110px"></svg-icon>
          </div>
          <div class="title">
            <svg-icon name="Slice" width="621px" height="108px">111</svg-icon>
          </div>
          <div class="middle" v-if="flag">
            <div class="account_box">
              <div class="user">
                <svg-icon name="account" width="32px" height="32px"></svg-icon>
                <el-input
                  class="input"
                  v-model="loginForm.username"
                  placeholder="输入账户名"
                ></el-input>
              </div>
              <span></span>
            </div>
            <div class="password_box">
              <div class="user">
                <svg-icon name="password" width="32px" height="32px"></svg-icon>
                <el-input
                  class="input"
                  v-model="loginForm.password"
                  show-password
                  placeholder="输入密码"
                ></el-input>
              </div>
              <span></span>
              <div class="forgetPassword">忘记密码?</div>
            </div>
            <!-- <el-input :prefix-icon="User"></el-input>
           <el-input :prefix-icon="Lock" show-password></el-input> -->
          </div>
          <div class="botton" @click="userLogin" v-if="flag">登录</div>
          <div class="botton2" v-if="flag" @click="toRegister">注册</div>
          <div class="loginSuccess" v-if="!flag">
            <svg-icon name="loading" class="svg"></svg-icon>
            <div class="title">登录成功，欢迎！</div>
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
// import { User, Lock } from '@element-plus/icons-vue'
import { ref } from 'vue'
//引入用户仓库
import useUserStore from '@/store/modules/user'
//获取路由器对象
import { useRoute, useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
//获取路由器对象
const $router = useRouter()
const $route = useRoute()
const userStore = useUserStore()
const loginForm = ref({ username: 'account', password: '111111' })
//控制登录以后登录成功的展示
const flag = ref<boolean>(true)
const userLogin = async () => {
  try {
    await userStore.userLogin(loginForm.value)
    let redirect: any = $route.query.redirect
    $router.push({ path: redirect || '/' })
    flag.value = false
  } catch (error) {
    ElMessage({
      type: 'error',
      message: '登录失败',
    })
  }
}
//点击去注册触发的事件
const toRegister = () => {
  $router.push('/register')
}
</script>

<style scoped lang="scss">
.contenter {
  width: 100vw;
  height: 100vh;
  background: url('../../../src/assets/images/background.png') no-repeat;
  background-size: cover;
  .right {
    margin-top: 110px;
    margin-left: 74px;
    // margin-bottom: 206px;
    margin-right: 259px;
    height: 683px;
    width: 621px;
    // background: pink;
    :deep(.el-input__wrapper) {
      background-color: transparent;
      box-shadow: none;
    }
    :deep(.el-input__inner) {
      color: #fff;
    }
    .top {
      margin-left: 261px;
      width: 110px;
      height: 110px;
      //  background: red;
    }
    .title {
      margin-top: 22px;
      width: 621px;
      height: 108px;
      //  background: skyblue;
    }
    .middle {
      margin-top: 63px;
      //  background: red;
      .account_box {
        .user {
          display: flex;
          .input {
            margin-left: 44px;
          }
          .input {
            margin-left: 44px;
            border-radius: 0px 0px 0px 0px;
            opacity: 0.8;
          }
        }
        span {
          display: block;
          margin-top: 10px;
          width: 621px;
          height: 1px;
          border: 1px solid #c2c9cf;
          opacity: 0.7;
        }
      }
      .password_box {
        margin-top: 52px;
        .user {
          display: flex;
          .input {
            margin-left: 44px;
          }
        }
        span {
          display: block;
          margin-top: 10px;
          width: 621px;
          height: 1px;
          border: 1px solid #c2c9cf;
          opacity: 0.7;
        }
        .forgetPassword {
          float: right;
          width: 79px;
          height: 22px;
          font-size: 16px;
          color: #ffffff;
          line-height: 19px;
        }
      }
    }
    .botton {
      margin-left: 101px;
      margin-top: 80px;
      margin-right: 90px;
      width: 430px;
      height: 55px;
      background: rgba(85, 137, 191, 0.2);
      border-radius: 4px 4px 4px 4px;
      border: 2px solid #5982f0;
      color: #e9f1fa;
      font-size: 22px;
      text-align: center;
      line-height: 50px;
      // background: pink;
    }
    .botton2 {
      margin-left: 101px;
      margin-top: 22px;
      margin-right: 90px;
      width: 430px;
      height: 55px;
      background: rgba(85, 137, 191, 0.2);
      border-radius: 4px 4px 4px 4px;
      border: 2px solid #5982f0;
      color: #e9f1fa;
      font-size: 22px;
      text-align: center;
      line-height: 50px;
      // background: pink;
    }
    .loginSuccess {
      display: flex;
      margin-top: 140px;
      margin-left: 199px;
      .svg {
        width: 19px;
        height: 19px;
      }
      .title {
        margin-top: 0;
        margin-left: 19px;
        font-size: 16px;
      }
    }
  }
}
</style>
